package com.demo.generics.meixianzhi;

/**
 * @Description:
 * @Author: xiangty
 * @Date: 2018-07-24
 * 为了告诉编译器,这个T是从哪里来,用两种方法
 * 1.定义泛型类
 * 2.定义泛型方法
 */
public class Cat<T> {

    public void eat(T food) {
        System.out.println("猫吃:" + food);
    }

    public static void main(String[] args) {
        Cat<String> cat1 = new Cat<String>();
        cat1.eat("字符串食物");

        Cat<Integer> cat2 = new Cat<Integer>();
        cat2.eat(1234);

        Cat<Person> cat3 = new Cat<Person>();
        cat3.eat(new Person());
    }
}
